package org.example.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.example.common.Result;
import org.example.pojo.Category;
import org.example.pojo.Goods;
import org.example.pojo.Query;
import org.example.service.GoodsService;
import org.example.mapper.GoodsMapper;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
* @author 13326
* @description 针对表【hards_goods】的数据库操作Service实现
* @createDate 2025-01-03 16:46:16
*/
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods>
    implements GoodsService{
    @Resource
    private GoodsMapper goodsMapper;
    @Override
    public Result getlist(Query query){
        LambdaQueryWrapper<Goods> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper
                .like(!StringUtils.isEmpty(query.getKeyword()), Goods::getGname,query.getKeyword())
                .eq(Goods::getGname,query.getKeyword());

        IPage<Goods> page=new Page<>(query.getPageNum(),query.getPageSize());
        goodsMapper.selectPageMap(page,query);
        HashMap<String,Object> map=new HashMap<>();
        map.put("total",page.getTotal());
        map.put("rows",page.getRecords());
        map.put("pages",page.getPages());
        map.put("size",page.getSize());
        return Result.ok(map);

    }
    @Override
    public Result add(Goods goods){
        int rows=goodsMapper.insert(goods);
        return Result.ok("新增成功");
    }
    @Override
    public Result updateGood(Goods goods){
        int rows=goodsMapper.updateById(goods);
        return Result.ok("修改成功");

    }
    @Override
    public Result deletegoods(Integer id){
        int rows=goodsMapper.deleteById(id);
        return Result.ok("删除成功");
    }
    @Override
    public Result selectbyid(Integer id,Integer busId){
        List<Goods> goods=goodsMapper.selectlist(id,busId);

        return Result.ok(goods);

    }

}




